<?php

class IndexAction extends CommAction
{
    public function index()
    {
        $this->display();
    }
    public function logout(){
        import('ORG.Util.Session');
        import('ORG.Util.Cookie');
        Session::destroy();
        Cookie::clear();
        $this->redirect('Login/login');
    }
    /**
     *  修改密码
     */
    public function changePwd(){
        $map=array();
        $map['id']=getLoginUid();
        $userInfo=D('Admin')->where($map)->find();
        $this->assign('admin',$userInfo);
        if(IS_POST){
            $data=$_POST;
            //todo 对输入做判断
            $this->checkEmpty($data['pwd1'],'请输入原密码');
            $this->checkEmpty($data['pwd2'],'请输入新密码');
            $this->checkEmpty($data['pwd3'],'请重复输入新密码');
            $map=array();
            $map['id']=getLoginUid();
            $oldPwd=D('Admin')->where($map)->getField('password');
            if($oldPwd!=$data['pwd1']){
                $this->error('原密码错误!');
            }
            if($data['pwd2']!=$data['pwd3']){
                $this->error('两次密码不一致!');
            }

            $data2['password']=$data['pwd2'];
            D('Admin')->where($map)->data($data2)->save();
            $this->success('修改成功',U('Admin/Index'));
            exit;
        }
        $this->display();
    }
    
    //测试数据加解密
    public function get_data_jiami(){
        $info = array('张三','李四','王五','jony');
        dump($info);
        dump(json_encode($info));
        dump(urlencode(json_encode($info)));
        dump(urldecode(urlencode(json_encode($info))));
        dump(json_decode(urldecode(urlencode(json_encode($info)))));
    }
  

    
}
